﻿namespace CommonUtils
{
    public class LanguageProvider
    {
        private string DictPath;

        /// <summary>
        /// 字典，如果访问量很大可以换成SafeMap
        /// </summary>
        public StringStringMap Dict;

        public LanguageProvider(LanguageType languageType)
        {
            DictPath = PathConfig.LanguageFolder.Combine(languageType + ".json");
            Dict = JsonUtil.DeserializeFromFile(DictPath, new StringStringMap(), false);
        }

        private void SaveDict()
        => FileUtil.Save(DictPath, Dict.ToJson());

        public string Get(string key)
        {
            if (!Dict.ContainsKey(key))
            {
                Dict[key] = key;
                SaveDict();
            }
            return Dict[key];
        }
    }
}
